<template>
	<view class="page">
		<view class="searchBox">
			<view class="inputBox">
				<view class="inputRow"  style="width: 100%;"  @click="dormShow=true">
					<view class="label" style="width: 70rpx;">
						{{language.exceptionAttendance.label1}}:
					</view>
					<view :class="params.roomCode ? 'val' : 'emty'">
						{{params.roomCode  ? params.roomCode  : language.exceptionAttendance.tip2 }}
						<!-- <u-input v-model="params.roomCode" :placeholder="language.exceptionAttendance.tip2"></u-input> -->
					</view>
				</view>
				<view class="inputRow" style="width: 50%;"  @click="departShow=true">
					<view class="label">
						{{language.exceptionAttendance.label2}}:
					</view>
					<view :class="selecetDepart.departName ? 'val' : 'emty'" >
						{{selecetDepart.departName  ? selecetDepart.departName  : language.exceptionAttendance.tip2 }}
					</view>
				</view>
				<view class="inputRow"  style="width: 50%;" @click="studentShow=true" >
					<view class="label">
						{{language.exceptionAttendance.label3}}:
					</view>
					<view :class="params.personName ? 'val' : 'emty'" >
						{{params.personName  ? params.personName  : language.exceptionAttendance.tip2 }}
						<!-- <u-input v-model="params.personName" :placeholder="language.exceptionAttendance.tip1"></u-input> -->
					</view>
				</view>
				<view class="inputRow">
					<view class="label">
						{{language.exceptionAttendance.label4}}:
					</view>
					<view :class="selectLabel ? 'val' : 'emty'" @click="selectListShow=true">
						{{selectLabel ? selectLabel : language.exceptionAttendance.tip2 }}
					</view>
				</view>
				<view class="inputRow" style="width: 100%;">
					<view class="label">
						{{language.exceptionAttendance.label5}}:
					</view>
					<view :class="params.attDate_begin ? 'val' : 'emty'" @click="attDate_beginShow=true">
						{{params.attDate_begin ? params.attDate_begin : language.exceptionAttendance.tip2 }}
					</view>
				</view>
				<view class="inputRow" style="width: 100%;">
						<view class="label">
							{{language.exceptionAttendance.label6}}:
						</view>
						<view :class="params.attDate_end ? 'val' : 'emty'" @click="attDate_endShow=true">
							{{params.attDate_end ? params.attDate_end : language.exceptionAttendance.tip2 }}
						</view>
				</view>
			</view>
			<view class="btnBox">
				<view class="btn"  @click="goSearch">
					{{language.exceptionAttendance.search}}
				</view>
			</view>
			
		</view>
		
			<scrollYBox styleText="height: calc( 100vh - 360rpx );" @scrolltolower="scrolltolower" :list="list">
						<template>
							<view style="padding-bottom: 50rpx;">
								<view class="boxItem" v-for="(item,index) in list" :key="index">
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{language.exceptionAttendance.label1}}
											</view>
											<view class="val">
												{{item.roomCode | emptyStr }}
											</view>
										</view>
										<view class="item ">
											<view class="label">
												{{language.exceptionAttendance.label2}}
											</view>
											<view class="val">
												{{item.deptId_dictText | emptyStr }}
											</view>
										</view>
									</view>
									<view class="row flex">
										<view class="item ">
											<view class="label">
												{{language.exceptionAttendance.label3}}
											</view>
											<view class="val">
												<!-- {{item.transAmt | emptyStr }} -->
												{{item.personId_dictText}}
											</view>
										</view>
										<view class="item ">
											<view class="label">
												{{language.exceptionAttendance.label4}}
											</view>
											<view class="val" style="color: #f56c6c;">
												{{item.exceptionTypes_dictText | emptyStr }}
											</view>
										</view>
									</view>
								<!-- 	<view class="row flex">
										<view class="item ">
											
										</view>
										<view class="item ">
											<view class="btn" @click="handleDetail(item)">
												核实登记
											</view>
										</view>
									</view> -->
								</view>
							</view>
						</template>
					</scrollYBox>
	
		<u-datetime-picker
		    :show="attDate_beginShow" ref="datetimePicker" v-model="attDate_begin" 
		    mode="date"  @cancel="attDate_beginShow=false" @confirm="attDate_beginConfirm"
		       ></u-datetime-picker>
		<u-datetime-picker
			:show="attDate_endShow" ref="datetimePicker" v-model="attDate_end" 
			mode="date"  @cancel="attDate_endShow=false" @confirm="attDate_endConfirm"
	       ></u-datetime-picker>
		<u-picker :show="selectListShow" :columns="selectList" keyName="label" @confirm="selectConfirm"
			@cancel="selectListShow = false"></u-picker>
		<u-picker :show="departShow" ref="uPicker" :columns="departColumns" @cancel="departShow=false" keyName="departName"
		  @confirm="depatConfirm" @change="departChangeHandler"></u-picker>
		<u-picker :show="dormShow" ref="uPicker2" :columns="dormColumns" @cancel="dormShow=false" keyName="roomCode"
		    @confirm="dormConfirm" ></u-picker>
		<u-picker :show="studentShow" ref="uPicker3" :columns="studentColumns" @cancel="studentShow=false" keyName="name"
			    @confirm="studentConfirm" ></u-picker>
	</view>
</template>

<script>
	import {dormAccessExceptionRecordListApi,dormRoomListApi,ssPersonListApi} from '@/common/api/commonApi/dormApi.js'
	import {getDepartBypidOridApi} from '@/common/api/commonApi/safeApi.js'
	export default {
		data() {
			return {
				list:[ ],
				params:{
					pageNo : 1,
					pageSize : 15,
					roomCode: '',
					personName: '',
					attDate_begin : '',
					attDate_end : '',
					exceptionTypes: '',
					deptId:'',
					status: 1,
				},
				attDate_begin: Number(new Date()),
				attDate_end: Number(new Date()),
				attDate_beginShow : false,
				attDate_endShow : false,
				total : 0,
				selectList : [
					[
						{
							label : '上午上课未打卡',
							val: 0
						},
						{
							label : '中午归寝未打卡',
							val: 1
						},
						{
							label : '下午上课未打卡',
							val: 2
						},
						{
							label : '下午离寝未打卡',
							val: 3
						},
						{
							label : '晚上归寝未打卡',
							val: 4
						},
						{
							label : '非规定时段打卡',
							val: 5
						},
						
					]
				],
				selectInfoAccount: uni.getStorageSync('selectInfoAccount'),
				selectLabel : '',
				selectListShow : false,
				deptName: '',
				departColumns: [
					[],[]
				],
				departColumnData: [
				],
				departShow :false,
				selecetDepart : {},
				dormShow : false,
				dormColumns: [
					[]
				],
				studentShow : false,
				studentColumns: [
					[]
				],
			}
		},
		components:{
		},
		methods: {
			studentConfirm(e){
				console.log(e);
				this.params.personName = e.value[0].name
				this.studentShow = false
			},
			getStudentList(){
				ssPersonListApi({
					departmentId : this.params.deptId,
					pageSize:1000,
					pageNo:1
				}).then(res=>{
					this.studentColumns[0] = []
					this.studentColumns[0] = res.result.records
				})
			},
			dormConfirm(e){
				console.log(e);
				this.params.roomCode = e.value[0].roomCode
				this.dormShow = false
			},
			getDormList(){
				dormRoomListApi({
					managerId : this.selectInfoAccount.id,
					pageSize:1000,
					pageNo:1
				}).then(res=>{
					this.dormColumns[0] = res.result.records
				})
			},
			departChangeHandler(e) {
			    const {
			        columnIndex,
			        value,
			        values, // values为当前变化列的数组内容
			        index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
			        picker = this.$refs.uPicker
			    } = e
			    // 当第一列值发生变化时，变化第二列(后一列)对应的选项
			   if (columnIndex === 0) {
			       // picker为选择器this实例，变化第二列对应的选项
			       // picker.setColumnValues(1, this.departColumnData[index])
			       picker.setColumnValues(1, value[index].children)
			   }else if(columnIndex==1){
					if(value[1].children&&value[1].children.length){
						picker.setColumnValues(2, value[1].children)
					}else{
						picker.setColumnValues(2, [])
					}
			   }
			},
			// 回调参数为包含columnIndex、value、values
			depatConfirm(e) {
			    console.log('confirm', e)
				this.selecetDepart = e.value[e.value.length-1] ? e.value[e.value.length-1] : e.value[e.value.length-2]
				this.params.deptId = this.selecetDepart.id
				this.getStudentList()
			    this.departShow = false
			},
			getDepart(){
				let params = {}
				let tempArr = this.selectInfoAccount.positionList
				let ids = []
				tempArr.forEach(item=>{
					ids.push(item.departmentId)
				})
				params.ids = ids.join(',')
				getDepartBypidOridApi(params).then(res=>{
					let arr = this.listToTree(res.result)
					console.log(arr);
					// this.departList = arr
					this.departColumnData = arr
					if(arr.length) this.departColumns[0] = arr
					if(arr.length && arr[0].children.length) this.departColumns[1] = arr[0].children
					if(arr.length && arr[0].children.length && arr[0].children[0].length) this.departColumns[2] = arr[0].children[0]
					// this.departColumns
					return console.log(arr);
				})
			},
			selectConfirm(e){
				console.log(e);
				this.selectLabel =  e.value[0].label
				this.params.exceptionTypes =  e.value[0].val
				this.selectListShow = false
			},
			handleDetail(item){
				this.goPage('/pages/componentsC/dorm/veriRegistration',{id:1})
			},
			scrolltolower(){
				if(this.total == this.list.length){
					return this.setMessage('没有更多了')
				}
				this.params.pageNo ++
				this.getList()
			},
			goSearch(){
				this.params.pageNo = 1 
				this.getList()
			},
			attDate_beginConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.attDate_begin = date
				console.log(this.params.attDate_begin);
				this.attDate_beginShow = false
			},
			attDate_endConfirm(e){
				let date = this.dateformat(e.value).split(' ')[0]
				this.params.attDate_end = date
				this.attDate_endShow = false
			},
			getList(){
				let params = this.params
				if(this.selecetDepart.id){
					params.deptId = this.selecetDepart.id
				}
				params.managerId = this.selectInfoAccount.id
				dormAccessExceptionRecordListApi(params).then(res=>{
					if(params.pageNo==1) this.list = []
					this.list = this.list.concat(res.result.records)
					this.total = res.result.total
				})
			},
			goSearch(){
				this.params.pageNo = 1
				this.getList()
			}
			
		},
		onLoad() {
			this.setPageTitle(this.language.exceptionAttendance.title)
			this.params.attDate_begin = this.dateformat(new Date()).split(' ')[0]
			this.params.attDate_end = this.dateformat(new Date()).split(' ')[0]
			this.getList()
			this.getDormList()
			this.getDepart()
			this.getStudentList()
		},
		onShow() {
			
		},
	}
</script>

<style lang="scss" scoped>
.page{
	background-color: #f1f1f1;
	// height: 100vh;
	.searchBox{
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 0 20rpx;
		border-bottom: 1px solid #f1f1f1;
		margin: 20rpx;
		border-radius: 8rpx;
		box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.16);
		.inputBox{
			flex: 1;
			// padding-right: 30rpx;
			display: flex;
			flex-wrap: wrap;
			.inputRow{
				min-height: 80rpx;
				display: flex;
				align-items: center;
				font-size: 32rpx;
				padding-left: 10rpx;
				.label{
					color: #191919;
					margin-right: 10rpx;
					// white-space: nowrap;
				}
			}
			.input{
				
			}
			.emty{
				color: #c0c4cc;
			}
			.val{
				
			}
		}
		.btnBox{
			display: flex;
			flex-direction: column;
			padding: 10rpx 0;
			.reset{
				margin-top: 20rpx;
				border: 1px solid #f1f1f1;
				background: #fff !important;
				color: #353535 !important;
			}
			.btn{
				padding: 0 30rpx;
				// width: 110rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #1890ff;
				border-radius: 8rpx;
				color: #fff;
			}
		}
	}
	
	.boxItem{
			background-color: #fff;
			margin: 20rpx;
			border-radius: 8rpx;
			padding: 10rpx;
			box-shadow: 0px 0px 20rpx 0px rgba(102,102,102,0.15);
			.row{
				margin: 10rpx;
				display: flex;
				.item{
					width: 50%;
					// flex: 1;
				}
				.label{
					color: #969696;
				}
				.val{
					color: #353535;
					font-size: 32rpx;
				}
				.btn{
						padding: 0 30rpx;
						width: 180rpx;
						height: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background: #1890ff;
						border-radius: 8rpx;
						color: #fff;
				}
			}
		}
		
}
</style>
